package Chapter2.Comparing.c9.Communication;

import java.util.Random;

public class Producer extends Thread {

    private Container<BaoZi> container;
    private Integer sum;

    /*public Producer(Integer sum) {
        this.sum = sum;
    }*/

    public Producer(Container<BaoZi> container, Integer sum, String name) {
        this(name);
        this.container = container;
        this.sum = sum;
    }

    public Producer(String name) {

    }

    /*public Producer(Container<String> container, int sum) {
    }*/

    @Override
    public void run() {
        String[] names = {"鲜肉包","香菇包","豆沙包","蟹黄包"};
        Random random = new Random();
        for(int i=0;i<sum;i++) {
            BaoZi baozi = new BaoZi(i+1,names[random.nextInt(4)]);
            System.out.println(Thread.currentThread().getName()+"做了一个："+baozi);
            container.save(baozi);
            try {
                Thread.sleep(random.nextInt(1000));
            }
            catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
